package com.itheima01.day05;

/**
 * @author 刘全
 * @date 2021/7/6
 */
/*
需求：设计一个方法用于获取数组中元素的最大值，和最小值
*/
public class MethodTest07 {
    public static void main(String[] args) {
        int[] a = {5, 8, 7, 3, 1};
        int[] mAM = maxAndMin(a);
        System.out.println("最大值:" + mAM[0]);
        System.out.println("最小值:" + mAM[1]);
    }

    public static int[] maxAndMin(int[] arr) {
        int max = arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (max < arr[i]) {
                max = arr[i];
            }
            if (min > arr[i]) {
                min = arr[i];
            }
        }
        int[] maxAndMin = {max, min};
        return maxAndMin;
    }
}
